fix(opac): stop injecting <br> between HTML paragraphs in descriptions (#313) - #314
fix(opac): stop injecting <br> between HTML paragraphs in descriptions (#313)#314fabiodalez-dev wants to merge 2 commits into
Conversation
#313) The book description and custom rich-text fields were rendered with sanitizeHtml(nl2br($value, false)). Editor (TinyMCE) HTML separates its <p> blocks with a literal "\n", so nl2br turned every inter-block newline into a stray <br> and double-spaced the output — reported on the OPAC with clean <p>…</p> source producing visible gaps between paragraphs. Add HtmlHelper::richText(): it applies nl2br only when the value is plain text (no block/line HTML), and leaves already-structured HTML untouched, so legacy imported descriptions still keep their newlines while editor HTML renders as authored. All five call sites (book description + custom fields on the OPAC book-detail and the admin scheda) now use it. Test: tests/richtext-nl2br-313.unit.php — HTML paragraphs render without an injected <br>, plain text keeps its breaks, block markers (br/div/ul/heading) suppress nl2br, sanitisation still strips scripts, and the reporter's Cyrillic data renders clean.
|
Warning Review limit reached
Next review available in: 59 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (4)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Fixes #313.
The bug
On the OPAC, a book description whose source is clean
<p>…</p>paragraphs rendered with visible extra spacing — a stray<br>between every paragraph.Cause
The book description was rendered with
sanitizeHtml(nl2br($value, false)). TinyMCE separates its<p>blocks with a literal\n, sonl2brturned every inter-block newline into a<br>:nl2bris only right for the other kind of description — legacy plain text imported with bare newlines.Fix
HtmlHelper::bookDescription()appliesnl2bronly when the value is plain text (no block/line HTML) and leaves already-structured HTML untouched, then sanitises. Plain-text descriptions keep their line breaks; editor HTML renders as authored. Both book-description call sites (the OPACbook-detailand the adminscheda) use it. Custom fields are intentionally unchanged, and no database migration rewrites stored content.Test
tests/richtext-nl2br-313.unit.php(12 checks): HTML paragraphs render without an injected<br>, plain text keeps its breaks, block markers (br/div/ul/heading) suppressnl2br, sanitisation still strips scripts, and the reporter's Cyrillic data renders clean. PHPStan level 5 clean.